const pagination = {


  state: {
    pageParams: {
      pageNum: localStorage.getItem('pageParams') ? localStorage.getItem('pageParams').pageNum : 1,
      pageSize: localStorage.getItem('pageParams') ? localStorage.getItem('pageParams').pageSize : 10
    }
  },
  mutations: {
    // 设置分页
    SET_PAGINATION(state, pageParams) {
      state.pageParams.pageNum = pageParams.pageNum
      state.pageParams.pageSize = pageParams.pageSize
      persistentStorage(pageParams)
    },

    // 重置分页
    RESET_SET_PAGINATION(state) {
      state.pageParams.pageNum = 1
      state.pageParams.pageSize = 10
      this.persistentStorage(state.pageParams)
    }
  },
  actions: {
    set_pagintaion({ commit }, pageParams) {
      commit('SET_PAGINATION', pageParams)
    },
    reset_pagintaion({ commit }) {
      commit('RESET_SET_PAGINATION')
    }
  },
}

// 持久化存储分页
const persistentStorage = pageParams => {
  localStorage.setItem('pageParams', JSON.stringify(pageParams))
}
export default pagination
